package com.huaxia.service;

import com.huaxia.dao.SalesDataMapper;
import com.huaxia.pojo.SalesData;
import com.huaxia.service.A_PV.PVService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * @author wangli 爱我华夏，爱我中华！
 * @date 2020/04/22 10:26
 */
@Service
public class SalesDataService {

    @Autowired
    private SalesDataMapper salesDataMapper;



    public SalesData getSalesData(){
        List<SalesData> salesDataList = salesDataMapper.getHuman();
        if(salesDataList==null||salesDataList.size()<=0){
            salesDataList = salesDataMapper.getHuman();
        }
        SalesData salesData = salesDataList.get(0);
        salesData.setDayAdvance(salesDataMapper.getdayAdvance());
        salesData.setDayInSure(salesDataMapper.getdayInSure());
        salesData.setMonthAdvance(salesDataMapper.getmonthAdvance());
        salesData.setMonthInSure(salesDataMapper.getmonthInSure());
        salesData.setYearInSure(salesDataMapper.getyearInSure());
        salesData.setRegisteredHuman(salesDataMapper.getRegisteredHuman());
        salesData.setCurrentMonthHuman(salesDataMapper.getCurrentMonthHuman());
        salesData.setDataTime(getTableTime());
        salesData.setYearTarget(salesDataMapper.findYxTarget());
        salesData.setSysUpdateTime(new SimpleDateFormat("yyyy-MM-dd HH:mm").format(new Date()));
        return salesData;
    }

    private String getTableTime(){
        Date date = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
        List<String> stringList = salesDataMapper.tableUpdateTime();
        if(stringList==null||stringList.size()<=0||"".equals(stringList.get(0))){
            return sdf.format(date);
        }
        return stringList.get(0);
    }
}
